package service;

import java.util.ArrayList;

import org.hibernate.*;

import util.HibernateUtil;

import core.*;

public class Tpdssdservice {
	private static SessionFactory sessions;
	
	public static ArrayList<Objetivos> getObjetivosDeEmpleado(String cuit){
		return getEmpleadoByCuit(cuit).getObjetivos();
	}

	public static Empleados getEmpleadoByCuit(String cuit){
		Empleados em = null;
		try {

			sessions = HibernateUtil.configureSessionFactory();

			Session session = sessions.openSession();
			Transaction tx = null;
			try {
				tx = session.beginTransaction(); //Inicia la transaccion
				Query query = session.createQuery("from Empleados where cuit = :cuit ");
				query.setParameter("cuit", cuit);
				em = (Empleados) query.list().get(0);
				
				
			} catch (Exception e) {
				e.printStackTrace();
				if (tx != null)
					tx.rollback();
				session.close();
			}
			session.disconnect();
			
		} catch (Exception e) {
			System.out
					.println("------------------------FAIL.------------------------");
			e.printStackTrace();
		}
		System.out.println(em.getNombres());
		return em;
	}
}
